define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'business/index' + location.search,
                    add_url: 'business/add',
                    // edit_url: 'business/edit',
                    // del_url: 'business/del',
                    multi_url: 'business/multi',
                    import_url: 'business/import',
                    table: 'business',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showColumns: false,

                showExport: false,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: 'LIKE'},
                        {field: 'nickname', title: __('Nickname'), operate: false},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'avatar', title: __('头像'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'money', title: __('下级充值金额'), operate: false, sortable: true},
                        {field: 'time', title: __('时间'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime, visible: false},
                        {field: 'operate', title: __('Operate'),
                            buttons: [
                                {
                                    name: 'fields',
                                    title: "查看下级",
                                    text: "查看下级",
                                    extend: "data-area='[\"\90%\"\,\"\90%\"\]'",
                                    url: 'junior/index',
                                    icon: 'fa fa-table',
                                    classname: 'btn btn-success btn-xs btn-execute btn-dialog'
                                }
                            ],
                            table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
